/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package plum.impl;

import java.util.Collection;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;

import org.eclipse.emf.common.util.EList;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;

import org.eclipse.emf.ecore.util.EObjectContainmentEList;
import org.eclipse.emf.ecore.util.EObjectResolvingEList;
import org.eclipse.emf.ecore.util.InternalEList;

import plum.ChoiceDecision;
import plum.ChoiceValue;
import plum.PlumPackage;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Choice Decision</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link plum.impl.ChoiceDecisionImpl#getMinSelected <em>Min Selected</em>}</li>
 *   <li>{@link plum.impl.ChoiceDecisionImpl#getMaxSelected <em>Max Selected</em>}</li>
 *   <li>{@link plum.impl.ChoiceDecisionImpl#getDefaultSelected <em>Default Selected</em>}</li>
 *   <li>{@link plum.impl.ChoiceDecisionImpl#getSelected <em>Selected</em>}</li>
 *   <li>{@link plum.impl.ChoiceDecisionImpl#getChoicevalues <em>Choicevalues</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class ChoiceDecisionImpl extends DecisionImpl implements ChoiceDecision {
	/**
	 * The default value of the '{@link #getMinSelected() <em>Min Selected</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getMinSelected()
	 * @generated
	 * @ordered
	 */
	protected static final int MIN_SELECTED_EDEFAULT = 0;

	/**
	 * The cached value of the '{@link #getMinSelected() <em>Min Selected</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getMinSelected()
	 * @generated
	 * @ordered
	 */
	protected int minSelected = MIN_SELECTED_EDEFAULT;

	/**
	 * The default value of the '{@link #getMaxSelected() <em>Max Selected</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getMaxSelected()
	 * @generated
	 * @ordered
	 */
	protected static final int MAX_SELECTED_EDEFAULT = 0;

	/**
	 * The cached value of the '{@link #getMaxSelected() <em>Max Selected</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getMaxSelected()
	 * @generated
	 * @ordered
	 */
	protected int maxSelected = MAX_SELECTED_EDEFAULT;

	/**
	 * The cached value of the '{@link #getDefaultSelected() <em>Default Selected</em>}' reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getDefaultSelected()
	 * @generated
	 * @ordered
	 */
	protected EList<ChoiceValue> defaultSelected;

	/**
	 * The cached value of the '{@link #getSelected() <em>Selected</em>}' reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getSelected()
	 * @generated
	 * @ordered
	 */
	protected EList<ChoiceValue> selected;

	/**
	 * The cached value of the '{@link #getChoicevalues() <em>Choicevalues</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getChoicevalues()
	 * @generated
	 * @ordered
	 */
	protected EList<ChoiceValue> choicevalues;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected ChoiceDecisionImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return PlumPackage.Literals.CHOICE_DECISION;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public int getMinSelected() {
		return minSelected;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setMinSelected(int newMinSelected) {
		int oldMinSelected = minSelected;
		minSelected = newMinSelected;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, PlumPackage.CHOICE_DECISION__MIN_SELECTED, oldMinSelected, minSelected));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public int getMaxSelected() {
		return maxSelected;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setMaxSelected(int newMaxSelected) {
		int oldMaxSelected = maxSelected;
		maxSelected = newMaxSelected;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, PlumPackage.CHOICE_DECISION__MAX_SELECTED, oldMaxSelected, maxSelected));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<ChoiceValue> getDefaultSelected() {
		if (defaultSelected == null) {
			defaultSelected = new EObjectResolvingEList<ChoiceValue>(ChoiceValue.class, this, PlumPackage.CHOICE_DECISION__DEFAULT_SELECTED);
		}
		return defaultSelected;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<ChoiceValue> getSelected() {
		if (selected == null) {
			selected = new EObjectResolvingEList<ChoiceValue>(ChoiceValue.class, this, PlumPackage.CHOICE_DECISION__SELECTED);
		}
		return selected;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<ChoiceValue> getChoicevalues() {
		if (choicevalues == null) {
			choicevalues = new EObjectContainmentEList<ChoiceValue>(ChoiceValue.class, this, PlumPackage.CHOICE_DECISION__CHOICEVALUES);
		}
		return choicevalues;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case PlumPackage.CHOICE_DECISION__CHOICEVALUES:
				return ((InternalEList<?>)getChoicevalues()).basicRemove(otherEnd, msgs);
		}
		return super.eInverseRemove(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case PlumPackage.CHOICE_DECISION__MIN_SELECTED:
				return getMinSelected();
			case PlumPackage.CHOICE_DECISION__MAX_SELECTED:
				return getMaxSelected();
			case PlumPackage.CHOICE_DECISION__DEFAULT_SELECTED:
				return getDefaultSelected();
			case PlumPackage.CHOICE_DECISION__SELECTED:
				return getSelected();
			case PlumPackage.CHOICE_DECISION__CHOICEVALUES:
				return getChoicevalues();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@SuppressWarnings("unchecked")
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case PlumPackage.CHOICE_DECISION__MIN_SELECTED:
				setMinSelected((Integer)newValue);
				return;
			case PlumPackage.CHOICE_DECISION__MAX_SELECTED:
				setMaxSelected((Integer)newValue);
				return;
			case PlumPackage.CHOICE_DECISION__DEFAULT_SELECTED:
				getDefaultSelected().clear();
				getDefaultSelected().addAll((Collection<? extends ChoiceValue>)newValue);
				return;
			case PlumPackage.CHOICE_DECISION__SELECTED:
				getSelected().clear();
				getSelected().addAll((Collection<? extends ChoiceValue>)newValue);
				return;
			case PlumPackage.CHOICE_DECISION__CHOICEVALUES:
				getChoicevalues().clear();
				getChoicevalues().addAll((Collection<? extends ChoiceValue>)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case PlumPackage.CHOICE_DECISION__MIN_SELECTED:
				setMinSelected(MIN_SELECTED_EDEFAULT);
				return;
			case PlumPackage.CHOICE_DECISION__MAX_SELECTED:
				setMaxSelected(MAX_SELECTED_EDEFAULT);
				return;
			case PlumPackage.CHOICE_DECISION__DEFAULT_SELECTED:
				getDefaultSelected().clear();
				return;
			case PlumPackage.CHOICE_DECISION__SELECTED:
				getSelected().clear();
				return;
			case PlumPackage.CHOICE_DECISION__CHOICEVALUES:
				getChoicevalues().clear();
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case PlumPackage.CHOICE_DECISION__MIN_SELECTED:
				return minSelected != MIN_SELECTED_EDEFAULT;
			case PlumPackage.CHOICE_DECISION__MAX_SELECTED:
				return maxSelected != MAX_SELECTED_EDEFAULT;
			case PlumPackage.CHOICE_DECISION__DEFAULT_SELECTED:
				return defaultSelected != null && !defaultSelected.isEmpty();
			case PlumPackage.CHOICE_DECISION__SELECTED:
				return selected != null && !selected.isEmpty();
			case PlumPackage.CHOICE_DECISION__CHOICEVALUES:
				return choicevalues != null && !choicevalues.isEmpty();
		}
		return super.eIsSet(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public String toString() {
		if (eIsProxy()) return super.toString();

		StringBuffer result = new StringBuffer(super.toString());
		result.append(" (minSelected: ");
		result.append(minSelected);
		result.append(", maxSelected: ");
		result.append(maxSelected);
		result.append(')');
		return result.toString();
	}

} //ChoiceDecisionImpl
